
//Cart
<?
$l_Image   	 = $_lang == 'vn' ? 'Image' : 'Image';
$l_product   = $_lang == 'vn' ? 'Product' : 'Product';
$l_quantity  = $_lang == 'vn' ? 'Quantity' : 'Quantity';
$l_price     = $_lang == 'vn' ? 'Unit price' : 'Unit price';
$l_money     = $_lang == 'vn' ? 'Cost' : 'Cost';
$l_total     = $_lang == 'vn' ? 'Total' : 'Total';

$l_btnDel    = $_lang == 'vn' ? 'Delete' : 'Delete';
$l_btnDelAll = $_lang == 'vn' ? 'Delete all' : 'Delete all';
$l_btnDontinue = $_lang == 'vn' ? 'Buy Continue' : 'Buy Continue';
$l_btnUpdate = $_lang == 'vn' ? 'Update' : 'Update';
$l_btnPay    = $_lang == 'vn' ? 'Pay' : 'Pay';

$l_cartEmpty = $_lang == 'vn' ? 'Your cart is empty.' : 'Your cart is empty.';

function checkexist(){
	$cart=$_SESSION['cart'];
	foreach ($cart as $product)
		if ($product[0]==$_REQUEST['p']) return true;
	return false;
}

if ($_REQUEST['act']=='del'){
	if (count($_SESSION['cart'])==1){
		unset($_SESSION['cart']);
	}else{
		$cart=$_SESSION['cart'];
		unset($cart[$_REQUEST['pos']]);
		$_SESSION['cart']=$cart;
	}
}

if (isset($_POST['butUpdate'])||isset($_POST['btnCheckout'])){
	$cart=$_SESSION['cart'];
	$t=0;
	foreach ($_POST['txtQuantity'] as $quantity){
		if (is_numeric($quantity) && $quantity>0 && strlen($quantity)<5)
			$cart[$t][1]=(int)$quantity;
		if ($quantity<=0){
			unset($cart[$t]);
			$t=$t-1;
		}
		$t=$t+1;
	}
	if (count($cart)<=0) unset($cart);
	$_SESSION['cart']=$cart;
	
	if (isset($_POST['btnCheckout'])) echo "<script>window.location='./?frame=registry'</script>";
}
	
if (isset($_POST['btnDeleteAll'])) unset($_SESSION['cart']);

if (isset($_POST['l_btnDontinue'])) echo "<script>window.location='./?frame=home'</script>";

if (isset($_REQUEST['p'])){
	if (!isset($_SESSION['cart'])){
		$pro=$_REQUEST['p'];
		$cart=array();
		$cart[] = array($pro,1);
		$_SESSION['cart']=$cart;
	}else{
		$pro=$_REQUEST['p'];
		$cart=$_SESSION['cart'];
		if (countRecord("tbl_product","id='".$_REQUEST['p']."'")>0 && checkexist()==false){
			$cart[]=array($pro,1);
			$_SESSION['cart']=$cart;
		}
	}
}else{
	$cart=$_SESSION['cart'];
}
?>


<? if (!isset($_SESSION['cart'])){?>
<table align="center" border="0" width="98%" cellpadding="0" cellspacing="0" >
	<tr><td height="5"></td></tr>
	<tr>
		<td>
			<table align="center" width="100%" cellpadding="0" cellspacing="0" class="border_table" bgcolor="#F5F7FB">
				<tr>
					<td align="center">
						<br><br>
						<font color="#0000FF" size="2" face="Verdana, Arial, Helvetica, sans-serif">
							<b><?=$l_cartEmpty?></b>
						</font>
						<br><br>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr><td height="5"></td></tr>
</table>
<? }else{?>


<FORM action="./" method="POST" name="frmCart">
<input type="hidden" name="frame" value="cart"> 
<table border="1" width="100%" cellspacing="0" cellpadding="4" style="border-collapse:collapse" class="border_table">
	<tr class="border_table" bgcolor="#F5F7FB">
		<th width="100"><span style="font-size:12px; font-family:Tahoma"><?=$l_Image?></span></th>
		<th class="smallfont border_table"><span style="font-size:12px; font-family:Tahoma"><?=$l_product?></span></th>
		<th class="smallfont border_table" width="70"><span style="font-size:12px; font-family:Tahoma">Quantity</span></th>
		<th class="smallfont border_table" width="70"><span style="font-size:12px; font-family:Tahoma"><?=$l_price?><br>(<font color="#CC0000">GBP</font>)</span></th>
		<th class="smallfont border_table" width="70"><span style="font-size:12px; font-family:Tahoma"><?=$l_money?></span></th>
		<th width="60"><span style="font-size:12px; font-family:Tahoma"><?=$l_btnDel?></span></th>
	</tr>
<?
$cnt=0;
$tongcong=0;
foreach ($cart as $product){
	$sql = "select * from tbl_product where id='".$product[0]."'";
	$result = mysql_query($sql,$conn);
	if (mysql_num_rows($result)>0){
	$pro = mysql_fetch_assoc($result)?>
	<tr>
		<td class="smallfont smallfont" align="center">	
			<?	
				$sql1 = "select * from tbl_product_category where id=".$pro['parent']." ";
				$result1 = @mysql_query($sql1,$conn);
				$pro1=mysql_fetch_assoc($result1); 
			?>		
			<A href="./?frame=product_detail&id=<?=$pro['id'];?>">
				<IMG src="<?=$pro1['image']; ?>" border=0 height="40px"/>
			</A>		
		</td>
		<td class="smallfont border_table"><?=$pro['name']?></td>
		<td class="smallfont border_table" align="center">
			<input type="text" name="txtQuantity[]" class="quantity" value="<?=$product[1]?>">
		</td>
		<td class="smallfont border_table" align="center"><?=$pro['price']?></td>
		<td class="smallfont border_table" align="center"><?=$pro['price']*$product[1]?></td>
		<td class="smallfont border_table" align="center">
        	<input type="submit" class="buttonorange" onmouseover="this.className='buttonblue'" onmouseout="this.className='buttonorange'" style="width:50" name="btnDelete" value="<?=$l_btnDel?>" onclick="window.location='./?frame=cart&act=del&pos=<?=$cnt?>';return false;">
	  </td>
	</tr>
<?
}
$tongcong=$tongcong+$pro['price']*$product[1];
$cnt=$cnt+1;
} 
?>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr><td height="10" colspan="2"></td></tr>
	<tr>
		<td class="smallfont" align="right" colspan="2">
			<b><?=$l_total?> : <font color="#CC0000"><?=$tongcong?></font> GBP</b>
		</td>
	</tr>
	<tr><td height="10" colspan="2"></td></tr>
	
</table>

</FORM>
<?
}
?>


// Trang cu
<script language="javascript">
function btnRegistry_onclick(){
	if(test_empty(document.frmRegistry.txtName.value)){
		alert(mustInput_Name);document.frmRegistry.txtName.focus();return false;
	}
	if(test_empty(document.frmRegistry.txtAddress.value)){
		alert(mustInput_Address);document.frmRegistry.txtAddress.focus();return false;
	}
	if(document.frmRegistry.cmbCountry.selectedIndex==0){
			alert(mustSelect_Country);return false;
	}
	if(test_empty(document.frmRegistry.txtEmail.value)){
		alert(mustInput_Email);document.frmRegistry.txtEmail.focus();return false;
	}
	if(!checkEmail(document.frmRegistry.txtEmail.value)){
		alert(invalid_Email);document.frmRegistry.txtEmail.focus();return false;
	}
	if(test_empty(document.frmRegistry.txtUid.value)){
		alert(mustInput_Uid);document.frmRegistry.txtUid.focus();return false;
	}
	if(!test_length4(document.frmRegistry.txtUid.value)){
		alert(mustLength4_Uid);document.frmRegistry.txtUid.focus();return false;
	}
	if(test_empty(document.frmRegistry.txtPwd.value)){
		alert(mustInput_Pwd);document.frmRegistry.txtPwd.focus();return false;
	}
	if(!test_length4(document.frmRegistry.txtPwd.value)){
		alert(mustLength4_Pwd);document.frmRegistry.txtPwd.value = '';document.frmRegistry.txtPwd.focus();return false;
	}
	if(test_empty(document.frmRegistry.txtPwd2.value)){
		alert(mustInput_Pwd2);document.frmRegistry.txtPwd2.focus();return false;
	}
	if(!test_length4(document.frmRegistry.txtPwd2.value)){
		alert(mustLength4_Pwd);document.frmRegistry.txtPwd2.value = '';document.frmRegistry.txtPwd2.focus();return false;
	}
	if(!test_confirm_pass(document.frmRegistry.txtPwd.value,document.frmRegistry.txtPwd2.value)){
		alert(identicalPassword);
		document.frmRegistry.txtPwd.value = '';
		document.frmRegistry.txtPwd2.value = '';
		document.frmRegistry.txtPwd.focus();return false;
	}
	if(test_empty(document.frmRegistry.txtRobust.value)){
		alert(mustInput_Robust);document.frmRegistry.txtRobust.focus();return false;
	}
	return true;
}
</script>
<?
$alphanum  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand = substr(str_shuffle($alphanum), 0, 5);
$randE = PKI_Encrypt($rand, 6733, 82393793)?>
<? $errMsg =''?>
<?
$l_Request     = $_lang == 'vn' ? 'Request info' : 'Request info';
$l_PerInfo     = $_lang == 'vn' ? 'Personal info' : 'Personal info';
$l_AddressInfo = $_lang == 'vn' ? 'Address info' : 'Address info';
$l_ContactInfo = $_lang == 'vn' ? 'Thông tin liên hệ' : 'Contact info';
$l_UserInfo    = $_lang == 'vn' ? 'User info' : 'User info';
$l_strConfirm  = $_lang == 'vn' ? 'Confirm string' : 'Confirm string';
$l_Male        = $_lang == 'vn' ? 'Nam' : 'Male';
$l_Female      = $_lang == 'vn' ? 'Nữ' : 'Female';
$l_Name        = $_lang == 'vn' ? 'Họ và tên' : 'Full name';
$l_Address     = $_lang == 'vn' ? 'Địa chỉ' : 'Address';
$l_State       = $_lang == 'vn' ? 'Tỉnh / Thành phố' : 'State';
$l_Country     = $_lang == 'vn' ? 'Quốc gia' : 'Country';
$l_Email       = $_lang == 'vn' ? 'Email' : 'Email';
$l_Uid         = $_lang == 'vn' ? 'Username' : 'Username';
$l_Pwd         = $_lang == 'vn' ? 'Password' : 'Password';
$l_Pwd2        = $_lang == 'vn' ? 'Confirm Your Password' : 'Confirm Your Password';
$l_strR        = $_lang == 'vn' ? 'Confirm string' : 'Confirm string';
$l_btnRegistry = $_lang == 'vn' ? 'Registry' : 'Registry';
$l_btnReset    = $_lang == 'vn' ? 'Reset' : 'Reset';
$l_RegSuccess  = $_lang == 'vn' ? 'Registry Successfully.' : 'Registry Successfully.';
$l_min4char    = $_lang == 'vn' ? 'Min 4 characters' : 'Min 4 characters';
////////////////pay ment
if (isset($_POST['btnPayment'])){
	$name       = trim($_POST['txtName']);
	$address    = trim($_POST['txtAddress']);
	$tel       = trim($_POST['txtTel']);
	$country    = $_POST['cmbCountry'];
	$tulapvn_Postcode_Order      			 = trim($_POST['txttulapvn_Postcode_Order']);	
	$tulapvn_SpecialInstructions_Order       = trim($_POST['txttulapvn_SpecialInstructions_Order']);	
	$tulapvn_CardholdersName       	= trim($_POST['txttulapvn_CardholdersName']);
	$tulapvn_TypeCard    = $_POST['cmbtulapvn_TypeCard'];	
	$tulapvn_CardNumber      		= trim($_POST['txttulapvn_CardNumber']);	
	$tulapvn_SecurityCode      		= trim($_POST['txttulapvn_SecurityCode']);	
	$YEAR   = $_POST['cmbYEAR'];
	$MONTH    = $_POST['cmbMONTH'];
	$tulapvn_BillingAddress       	= trim($_POST['txttulapvn_BillingAddress']);	
	$tulapvn_Postcode       		= trim($_POST['txttulapvn_Postcoder']);						
	$tulapvn_Country    = $_POST['cmbtulapvn_Country'];	
	$email      = trim($_POST['txtEmail']);

			$fields_arr = array(
				"name"          => "'$name'",
				"address"       => "'$address'",
				"tel"          => "'$tel'",	
				"country"       => "'$country'",
				"tulapvn_Postcode_Order"       => "'$tulapvn_Postcode_Order'",
				"tulapvn_SpecialInstructions_Order"       => "'$tulapvn_SpecialInstructions_Order'",								
				"tulapvn_CardholdersName"       => "'$tulapvn_CardholdersName'",
				"tulapvn_TypeCard"       => "'$tulapvn_TypeCard'",
				"tulapvn_CardNumber"       => "'$tulapvn_CardNumber'",								
				"tulapvn_SecurityCode"       => "'$tulapvn_SecurityCode'",
				"tulapvn_ExpiryDate"       => "'$YEAR&$MONTH'",
				"tulapvn_BillingAddress"       => "'$tulapvn_BillingAddress'",								
				"tulapvn_Postcode"       => "'$tulapvn_Postcode'",								
				"tulapvn_Country"       => "'$tulapvn_Country'",					
				"email"         => "'$email'",
				"status"        => "0",
				"date_added"    => "now()",
				"last_modified" => "now()",
			);
				$result = insert("tbl_member",$fields_arr);
			
				// Code gui email
          

               $to=" tulapvn@gmail.com ";
               mail( $to, "Full name: $name" );
             
     //if($result) {
				//$_SESSION['member'] = $uid;
				echo "<script>window.location='./?frame=thank_you'</script>";		
				
}

//////////////and pay ment
if (isset($_POST['btnRegistry'])){
	$name       = trim($_POST['txtName']);
	$address    = trim($_POST['txtAddress']);
	$tel       = trim($_POST['txtTel']);
	$country    = $_POST['cmbCountry'];
	$tulapvn_Postcode_Order      			 = trim($_POST['txttulapvn_Postcode_Order']);	
	$tulapvn_SpecialInstructions_Order       = trim($_POST['txttulapvn_SpecialInstructions_Order']);	
	$tulapvn_CardholdersName       	= trim($_POST['txttulapvn_CardholdersName']);
	$tulapvn_TypeCard    = $_POST['cmbtulapvn_TypeCard'];	
	$tulapvn_CardNumber      		= trim($_POST['txttulapvn_CardNumber']);	
	$tulapvn_SecurityCode      		= trim($_POST['txttulapvn_SecurityCode']);	
	$YEAR   = $_POST['cmbYEAR'];
	$MONTH    = $_POST['cmbMONTH'];
	$tulapvn_BillingAddress       	= trim($_POST['txttulapvn_BillingAddress']);	
	$tulapvn_Postcode       		= trim($_POST['txttulapvn_Postcoder']);						
	$tulapvn_Country    = $_POST['cmbtulapvn_Country'];	
	$email      = trim($_POST['txtEmail']);
	$uid        = trim($_POST['txtUid']);
	$pwd        = trim($_POST['txtPwd']);
	$Rdx        = isset($_POST['HidRd']) ? trim($_POST['HidRd']) : "";
	$strRobust  = isset($_POST['txtRobust']) ? trim($_POST['txtRobust']) : "";
	if (md5($strRobust) == $Rdx){
		$uidTest = getRecord("tbl_member","uid='".$uid."'");
		if($uidTest['uid']==$uid){
			$errMsg = '"Tên đăng nhập" này đã tồn tại. Hãy chọn tên khác !';
		}else{
			$fields_arr = array(
				"name"          => "'$name'",
				"address"       => "'$address'",
				"tel"          => "'$tel'",	
				"country"       => "'$country'",
				"tulapvn_Postcode_Order"       => "'$tulapvn_Postcode_Order'",
				"tulapvn_SpecialInstructions_Order"       => "'$tulapvn_SpecialInstructions_Order'",								
				"tulapvn_CardholdersName"       => "'$tulapvn_CardholdersName'",
				"tulapvn_TypeCard"       => "'$tulapvn_TypeCard'",
				"tulapvn_CardNumber"       => "'$tulapvn_CardNumber'",								
				"tulapvn_SecurityCode"       => "'$tulapvn_SecurityCode'",
				"tulapvn_ExpiryDate"       => "'$YEAR&$MONTH'",
				"tulapvn_BillingAddress"       => "'$tulapvn_BillingAddress'",								
				"tulapvn_Postcode"       => "'$tulapvn_Postcode'",								
				"tulapvn_Country"       => "'$tulapvn_Country'",					
				"email"         => "'$email'",
				"uid"           => "'$uid'",
				"pwd"           => "'$pwd'",
				"status"        => "0",
				"date_added"    => "now()",
				"last_modified" => "now()",
			);
			
			$result = insert("tbl_member",$fields_arr);
			if($result) {
				$_SESSION['member'] = $uid;
				echo "<script>window.location='./?frame=registry&code=1'</script>";
			}
		}
	}else{
		$errMsg = 'Sai "Chuỗi xác nhận" !';
	}
}
if ($_REQUEST['code']=='1'){
?>

<table align="center" border="0" width="98%" cellpadding="0" cellspacing="0">
	<tr><td height="5"></td></tr>
	<tr>
		<td>
			<table align="center" border="1" width="100%" cellpadding="0" bordercolor="#FFFFFF" cellspacing="0" style="border-collapse:collapse">
				<tr>
					<td align="center">
						<br><br>
						<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">
						<b><?=$l_RegSuccess?></b>
						</font>
						<br><br>
						[ <a href="./"><?=$_lang=='vn'?'Click here to return to home page!':'Login'?></a> ] Or
						<BR /><BR />
						<a href="./?frame=cart" class="link">
				  	  <img src="images/cart.jpg" width="20" height="17" vspace="2" border="0" align="absmiddle" />Go to Cart</a>
						<br/><br/>
						
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr><td height="5"></td></tr>
</table>

<?
}else{
?>

<form method="POST" name="frmRegistry" action="./">
<input type="hidden" name="frame" value="registry">
<table align="center" border="0" width="98%" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<table align="center" border="1" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse" bordercolor="#CCCCCC">
				<tr>
					<td align="center">

<table border="0" cellspacing="5" cellpadding="0" width="100%" align="center">
	<tr>
		<td height="20" colspan="3" class="normalfont" align="right">
			<font color="#FF0000">* </font><font color="#000000"><?=$l_Request?>&nbsp;&nbsp;&nbsp;</font>
		</td>
	</tr>

	<tr><td height="20" colspan="3" class="normalTitle"><b>Personal Customer Information</b><HR size="1" noshade></td></tr>

	<tr>
		<td align="right" class="normalFont">Full Name</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txtName" value="<?=$name?>"></td>
	</tr>
	<tr>
		<td align="right" class="normalFont">Email</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txtEmail" value="<?=$email?>"></td>
	</tr>
	<tr>
		<td align="right" class="normalFont">Telephone Number</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txtTel" value="<?=$tel?>"></td>
	</tr>	
	<tr>
		<td align="right" class="normalFont">Delivery Address</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txtAddress" value="<?=$address?>"></td>
	</tr>
	<tr valign="middle" height="22">
		<td align="right" class="normalFont">Country</td>
		<td><font color="#FF0000">*</font></td>
		<td>
			<?=comboCountry($country,$_lang)?>
		</td>
	</tr>	
	<tr>
		<td align="right" class="normalFont">Postcode</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txttulapvn_Postcode_Order" value="<?=$tulapvn_Postcode_Order?>"></td>
	</tr>
	<tr>
		
	</tr>
	<tr><td height="20" colspan="3" class="normalTitle"></td></tr>
	<tr><td height="20" colspan="3" class="normalTitle"><B>Customer Billing & Payment Details</B><HR size="1" noshade></td></tr>
	<tr>
		<td align="right" class="normalFont">Cardholders Name</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txttulapvn_CardholdersName" value="<?=$tulapvn_CardholdersName?>"></td>
	</tr>
	<tr>
		<td align="right" class="normalFont">Type of Card</td>
		<td><font color="#FF0000">*&nbsp;&nbsp;&nbsp;  </font></td>
		<td>
			<?=combotulapvn_TypeCard($tulapvn_TypeCard,$_lang)?>	
		</td>
	</tr>	
	<tr>
		<td align="right" class="normalFont">Card Number</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txttulapvn_CardNumber" value="<?=$tulapvn_CardNumber?>"></td>
	</tr>
	<tr>
		<td align="right" class="normalFont">CVV - 3 Digit Security Code</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txttulapvn_SecurityCode" value="<?=$tulapvn_SecurityCode?>">
			<img src="images/cvv.png" />
		</td>
	</tr>
	<tr>
		<td align="right" class="normalFont">Expiry Date</td>
		<td><font color="#FF0000">*&nbsp;&nbsp;&nbsp;</font></td>
		<td>
			<table>
				<tr>
					<td >
											<?=comboMONTH($MONTH,$_lang)?>			
					</td>
					<td>
											<?=comboYEAR($YEAR,$_lang)?>		
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td align="right" class="normalFont">Card Billing Address</td>
		<td><font color="#FF0000">*</font></td>
		<td><textarea class="textbox" size="30" name="txttulapvn_BillingAddress" value="<?=$tulapvn_BillingAddress?>"></textarea></td>
	</tr>	
	<tr valign="middle" height="22">
		<td align="right" class="normalFont">Country</td>
		<td><font color="#FF0000">*</font></td>
		<td>
			<?=combotulapvn_Country($tulapvn_Country,$_lang)?>
		</td>
	</tr>	
	<tr>
		<td align="right" class="normalFont">Postcode</td>
		<td><font color="#FF0000">*</font></td>
		<td><input class="textbox" size="30" name="txttulapvn_Postcode" value="<?=$tulapvn_Postcode?>"></td>
	</tr>
		<tr>
		<td align="right" class="normalFont"></td>
		<td><font color="#FF0000"></td>
		<td><br />
			<input style="WIDTH: 152px; HEIGHT: 22px" class="buttonorange"  name="btnPayment" value="Submit Payment" type="submit">
			<input style="WIDTH: 89px; HEIGHT: 22px" class="buttonorange"  name="butReset" value="Reset" type="reset">
			<br>		
		</td>
	</tr>
	
				
	<tr><td height="20" colspan="3" class="normalTitle"></td></tr>		
	<tr>
		
	</tr>


	
	
	
	
	
	
	
	

	
	
	<tr><td colspan="3" height="10"></td></tr>
</table>

					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr><td height="5"></td></tr>
</table>
</form>

<? }?>
<? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>